package package1;

import java.net.MalformedURLException;
import java.text.ParseException;
import java.util.List;

import schneider.mstt.api.ISPoTService;
import schneider.mstt.api.ProjectDTO;
import schneider.mstt.api.exceptions.MSTTSynchroException;

import com.caucho.hessian.client.HessianProxyFactory;
import com.caucho.hessian.client.HessianRuntimeException;

import fr.sciforma.psconnect.service.exception.TechnicalException;

public class Test3 implements ISPoTService
{
   private ISPoTService iSPoTService;

   private String _url;

   public Test3(String url, String login, String password)
   {

      HessianProxyFactory factory = new HessianProxyFactory();

      factory.setHessian2Reply(true);
      factory.setHessian2Request(true);

      // factory.setUser(login);
      // factory.setPassword(password);

      _url = url;

      try
      {
         iSPoTService = (ISPoTService) factory.create(ISPoTService.class, _url);
      }
      catch (MalformedURLException e)
      {
         throw new TechnicalException(e, "problem with URL <" + _url + ">");
      }
   }

   public List<String> getProjectIds(String owningOrga, String type) throws MSTTSynchroException
   {
      try
      {
         return iSPoTService.getProjectIds(null, null);
      }
      catch (HessianRuntimeException e)
      {
         throw new TechnicalException(e, "problem with remote url <" + _url + ">");
      }
   }

   public String getProject(String SPoTInternalId) throws MSTTSynchroException
   {

      try
      {
         return iSPoTService.getProject(SPoTInternalId);
      }
      catch (HessianRuntimeException e)
      {
         throw new TechnicalException(e, "problem with remote url <" + _url + ">");
      }
   }

   public static void main(String[] args) throws MSTTSynchroException, ParseException
   {
      Test3 test3 = new Test3("http://localhost:8080/spot-mstt-synchro-projects-server/SPoTServletImpl", null, null);
      String mm = test3.getProject("41414");

      System.out.println(ProjectDTO.getInstanceFromString(mm).getId());

   }
}
